<template>
	<view class="login">
		<view class="t1">
			<image :src="imgUrl+'1.png'" mode="widthFix"></image>
		</view>
		<view class="t3">
			<view>
				<view>
					<image :src="imgUrl+'login_sjh.png'" mode="widthFix"></image>
					<input v-model="phone" placeholder-style="color:#CCCCCC" type="number" placeholder="请输入手机号码">
				</view>
			</view>
			<view>
				<view>
					<image :src="imgUrl+'login_yzm.png'" mode="widthFix"></image>
					<input v-model="code" placeholder-style="color:#CCCCCC" type="number" placeholder="请输入验证码">
				</view>
				<text class="getCode" @click="getCode">{{tips ||'获取验证码'}}</text>
			</view>
		</view>
		<view class="b2" @click="login">
			确定
		</view>
		<view class="t4" @click="isActive =!isActive">
			<image v-if="isActive" :src="imgUrl+'21.png'" mode="widthFix"></image>
			<image v-else :src="imgUrl+'22.png'" mode="widthFix"></image>
			勾选即表示您已同意 <text @click.stop="goTo('/pages/commer/PrivacyPolicy')">《Donco Bakey用户协议》</text>
		</view>
		<u-code :seconds="seconds" ref="uCode" @change="codeChange"></u-code>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				tips: '',
				imgUrl: this.imgUrl,
				seconds: 60,
				acitve: 0,
				// phone: "15914137094",
				// code: "123123a",
				phone: "",
				code: "",
				loginId: 0,
				isActive: true
			}
		},
		computed: {

		},
		onLoad(option) {
			this.loginId = option.id
		},
		onShow() {
			this.$a.GetOpenToken()

		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {

				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					if (!this.phone) {
						uni.showToast({
							title: "请填写手机号码",
							icon: 'none'
						})
						return;
					}
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$http.getSmsCode({
						mobile: this.phone
					}).then(res => {
						uni.hideLoading();
						if (res.code == 0) {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
							this.$refs.uCode.start();
						}
						// setTimeout(() => {
						// 	uni.hideLoading();
						// 	// 这里此提示会被this.start()方法中的提示覆盖
						// 	uni.$u.toast('验证码已发送');
						// 	// 通知验证码组件内部开始倒计时

						// }, 2000);
					})

				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},

			login() {
				if (this.isActive) {
					uni.showToast({
						title: "请勾选用户协议",
						icon: 'none'
					})
					return;
				}
				if (!this.phone) {
					uni.showToast({
						title: "请填写手机号码",
						icon: 'none'
					})
					return
				}
				if (!this.code) {
					uni.showToast({
						title: "请输入验证码",
						icon: 'none'
					})
					return
				}

				uni.showLoading({
					title: "请稍等"
				})
				this.$http.wxBindPhone({
					mobile: this.phone,
					yzm: this.code,
					id: this.loginId,
					registration_Id: "",
					scene: ""
				}).then(res => {
					uni.hideLoading()
					if (res.code == 0) {
						// uni.setStorageSync('u_token',res.content.data.access_token)
						// uni.setStorageSync('userInfo',res.content.member)
						uni.setStorageSync('u_token', res.data.access_token)
						uni.setStorageSync('userInfo', res.member)
						uni.setStorageSync("isLogin", true);
						this.goTo("/pages/index/index?page=my");
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>



<style lang="scss" scoped>
	.login {
		text-align: center;
		margin-top: 200upx;

		.t1 {
			image {
				width: 380upx;
				height: 100upx;
			}
		}

		.t2 {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 40upx;
			font-size: 34upx;
			font-weight: 400;
			margin-bottom: 70upx;
			font-size: 34upx;
			font-weight: 400;
			color: #999999;

			view {
				margin: 0 50upx;
				padding-bottom: 6upx;
			}

			.acitve {
				font-size: 34upx;
				font-weight: 500;
				color: #1E7166;
				border-bottom: 2px solid #1E7166;
			}
		}

		.t3 {
			width: 660upx;
			margin: 0 auto;
			background: #FFFFFF;
			border-radius: 10upx;
			padding: 40upx 25upx;
			text-align: left;

			>view {
				display: flex;
				border-bottom: 1px solid #F8F8F8;
				padding-bottom: 40upx;
				justify-content: space-between;
				align-items: center;

				>view {
					display: flex;
					align-items: center;
				}

				.getCode {
					font-size: 24upx;
					display: inline-block;
					width: 160upx;
					text-align: center;
					font-weight: 400;
					color: #BFB49B;
					border-left: 1px solid #ccc;

				}
			}

			>view:last-child {
				padding-bottom: 0;
				margin-top: 40upx;
				border-bottom: 0;
			}

			image {
				width: 40upx;
				height: 40upx;
				margin-right: 16upx;
			}
		}

		.b2 {
			width: 660rpx;
			height: 80upx;
			line-height: 80upx;
			margin: 60upx auto 0;
			background: linear-gradient(270deg, #01AD65 0%, #01AD65 65%, #01AD65 100%);
			border-radius: 100upx;
			font-size: 32upx;
			font-weight: 400;
			color: #F8F7F7;
		}

		.t4 {
			margin-top: 27upx;
			font-size: 20upx;
			font-weight: 400;
			color: #888888;
			display: flex;
			align-items: center;
			justify-content: center;

			image {
				width: 30upx;
				height: 30upx;
				margin-right: 10upx;
			}

			text {
				color: #BFB49B;
			}
		}
	}
</style>
